package top.bingoz.wanandroid.ui.adapter

import android.content.Context
import com.alibaba.android.vlayout.LayoutHelper
import com.alibaba.android.vlayout.layout.GridLayoutHelper
import com.scwang.smartrefresh.layout.util.DensityUtil
import jp.wasabeef.glide.transformations.RoundedCornersTransformation
import kotlinx.android.synthetic.main.item_image.view.*
import top.bingoz.wanandroid.R
import top.bingoz.wanandroid.bean.Image
import top.bingoz.wanandroid.common.app.TransformationManagers
import top.bingoz.wanandroid.common.bindings.Bindings

class ImageAdapter(context: Context) : BaseAdapter<Image>(context) {
    override fun getLayoutId(): Int {
        return R.layout.item_image
    }

    override fun onCreateLayoutHelper(): LayoutHelper {
        val helper = GridLayoutHelper(2)
        return helper
    }


    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val item = getItem(position)
//        Bindings.setImageUri(holder.itemView.ivCover, item.image_url, transformation = TransformationManagers.cropCircle())
//        Bindings.setImageUri(holder.itemView.ivCover, item.image_url, transformation = TransformationManagers.cropSquare())
        Bindings.setImageUri(holder.itemView.ivCover, item.image_url, transformation = TransformationManagers.round(DensityUtil.dp2px(10f), 0, RoundedCornersTransformation.CornerType.ALL))
    }

}